<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

</head>

<body>
    <h1>axios的请求别名使用</h1>
    <button id="getmsg">查询信息请求getmsg</button>
    <button id="addmsg">添加信息请求addmsg</button>
    <button id="updatamsg">修改信息请求updatamsg</button>
    <button id="deletemsg">删除信息请求deletemsg</button>

    <script>
        const getmsg = document.getElementById('getmsg')
        const addmsg = document.getElementById('addmsg')
        const updatamsg = document.getElementById('updatamsg')
        const deletemsg = document.getElementById('deletemsg')

        getmsg.onclick = async function () {
            try {
                const re = await axios.get('/getmsg', {
                    params: {
                        userId: '001'
                    }
                })
            console.log(re.data)
              } catch(e){
                console.log(e);
            }
        }

        addmsg.onclick = async function () {
            try {
                const re = await axios.post('/addmsg',{
                    name:'杨幂',
                    sex:'女',
                    age:36
                   } )
            console.log(re.data)
              } catch(e){
                console.log(e);
            }
        }


        updatamsg.onclick = async function () {
            try {
                const re = await axios.put('/updatamsg', {
                    name:'池昌旭',
                    sex:'男',
                    age:34
                })
            console.log(re.data)
              } catch(e){
                console.log(e);
            }
        }


        deletemsg.onclick = async function () {
            try {
                const re = await axios.delete('/deletemsg', {
                    params: {
                        userId: '001'
                    }
                })
            console.log(re.data)
              } catch(e){
                console.log(e);
            }
        }
    </script>
</body>

</html>